package com.shujia.wyh.mr.harrypotter;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//The books chronicle the adventures of the adolescent wizard Harry Potter and his best friends Ron Weasley and Hermione Granger, all of whom are students at Hogwarts School of Witchcraft and Wizardry.
public class MyHarryMapper extends Mapper<LongWritable, Text,Text,LongWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        String s = value.toString();
        String line = s.replaceAll(",", "").replaceAll("\\.", "");
        String[] s1 = line.split(" ");
        for (String s2 : s1) {
            String s3 = s2.toLowerCase();
            context.write(new Text(s3),new LongWritable(1L));
        }
    }
}
